
Public Class FrmDisplayGrid

  Public sCallingControl As String
  Public sCallingPurpose As Integer
  Public sEnteredMainName As String


  Private Sub LoadTagValues()
    Dim iRow As Integer = 0

    Dim objTags As New clsTags

    Me.Text = "Tag Value Details"
    Me.StartPosition = FormStartPosition.Manual

    With dgvResult
      .ColumnCount = 3
      .Columns(0).HeaderText = "Tag Code"
      .Columns(0).Width = 120
      .Columns(1).HeaderText = "Tag Description"
      .Columns(1).Width = 150
      .Columns(2).HeaderText = "Tag Value"
      .Columns(2).Width = 40
    End With

    mPrRefreshConn()
    objTags.fnSelectAllTags()

    While objTags.mDrTags.Read()

      With dgvResult
        .RowCount = .RowCount + 1
        .Rows(iRow).Cells(0).Value = objTags.mDrTags("TAGS_FIXX_CODE").ToString
        .Rows(iRow).Cells(1).Value = objTags.mDrTags("TAGS_FIXX_NAME").ToString
        .Rows(iRow).Cells(2).Value = objTags.mDrTags("TAGS_FIXX_VALU").ToString
      End With

      iRow = iRow + 1

    End While

    DBDisconnect()

  End Sub

  Private Sub LoadConstantValues()
    Dim iRow As Integer = 0

    Dim objCnst As New clsCnst
    Me.Text = "Constant Values"
    Me.StartPosition = FormStartPosition.Manual

    With dgvResult
      .ColumnCount = 2
      .Columns(0).HeaderText = "Constant Name"
      .Columns(0).Width = 175
      .Columns(1).HeaderText = "Constant Value"
      .Columns(1).Width = 150
    End With

    mPrRefreshConn()

    objCnst.select_all_CNST()

    While objCnst.dr_cnst.Read()

      With dgvResult
        .RowCount = .RowCount + 1
        .Rows(iRow).Cells(0).Value = objCnst.dr_cnst("CNST_CNST_NAME").ToString
        .Rows(iRow).Cells(1).Value = objCnst.dr_cnst("CNST_CNST_VALU").ToString

      End With

      iRow = iRow + 1

    End While

    DBDisconnect()
  End Sub

  Private Sub LoadSubClassNames()
    Dim iRow As Integer = 0
    Dim objMcls As New clsMainclass
    Dim objScls As New clsScls
    Dim iMainClsID As Integer
    Dim sSubMainName As String
    Dim sSubClsName As String
    Dim iCount As Integer

    Me.Text = "Sub Class Details"
    Me.StartPosition = FormStartPosition.Manual

    With dgvResult
      .ColumnCount = 2
      .Columns(0).HeaderText = "Main Class Name"
      .Columns(0).Width = 165
      .Columns(1).HeaderText = "SubClass Name"
      .Columns(1).Width = 165
    End With

    'For a member being add default sub classes

    With dgvResult

      .Rows.Add(2)
      .Rows(0).Cells(0).Value = "Global"
      .Rows(0).Cells(1).Value = "Header"
      .Rows(1).Cells(0).Value = "Global"
      .Rows(1).Cells(1).Value = "Trailer"

    End With

    'For a member being add sub classes as in the database

    mPrRefreshConn()
    iCount = 2

    objMcls.fnSelectAllMcls()

    While objMcls.mDrMainClass.Read
      sSubMainName = objMcls.mDrMainClass("MCLS_NAME").ToString()
      iMainClsID = objMcls.mDrMainClass(0).ToString()


      If iMainClsID <> 0 Then

        objScls.mIntSubClassMclsId = iMainClsID

        objScls.fnSelectSclsBasdMcls()

        While objScls.mDrSubClass.Read

          sSubClsName = objScls.mDrSubClass("SCLS_CLAS_NAME").ToString()

          dgvResult.RowCount = dgvResult.RowCount + 1
          dgvResult.Rows(iCount).Cells(0).Value = sSubMainName
          dgvResult.Rows(iCount).Cells(1).Value = sSubClsName
          iCount = iCount + 1

        End While

      End If

    End While

    objMcls = Nothing
    objScls = Nothing

    DBDisconnect()

    'For a member being add sub classes added so far in the application

    For iRow = 0 To (frmStructureGenerator.iSubClassCounter - 1)

      With dgvResult
        .RowCount = .RowCount + 1
        .Rows(iRow + iCount).Cells(0).Value = frmStructureGenerator.txtMainClass.Text
        .Rows(iRow + iCount).Cells(1).Value = frmStructureGenerator.sSubClassArray(iRow)
      End With
    Next

  End Sub

  Private Sub LoadMainClasses()

  End Sub

  Private Sub LoadTables()
    Dim iRow As Integer = 0

    Dim objTags As New clsTags

    Me.Text = "Table Details"
    Me.StartPosition = FormStartPosition.Manual

    With dgvResult
      .ColumnCount = 4
      .Columns(0).HeaderText = "Table Name"
      .Columns(0).Width = 180
      .Columns(1).HeaderText = "Table Client"
      .Columns(1).Width = 80
      .Columns(2).HeaderText = "Short Name"
      .Columns(2).Width = 80
      .Columns(3).HeaderText = "Table Id"
      .Columns(3).Width = 80
      .Columns(3).Visible = False
    End With

    mPrRefreshConn()
    objTags.fnSelectAllTables()

    While objTags.mDrTags.Read()

      With dgvResult
        .RowCount = .RowCount + 1
        .Rows(iRow).Cells(0).Value = objTags.mDrTags("tabm_table_name").ToString
        .Rows(iRow).Cells(1).Value = objTags.mDrTags("tabm_clnt_srvr_indc").ToString
        .Rows(iRow).Cells(2).Value = objTags.mDrTags("tabm_table_short_name").ToString
        .Rows(iRow).Cells(3).Value = objTags.mDrTags("tabm_table_id").ToString
      End With

      iRow = iRow + 1

    End While

    DBDisconnect()

  End Sub

  Private Sub ReturnTagValues(ByVal aRoeIndex As Integer)

    With dgvResult
      If sCallingControl = "txtMemTagValue" Then
        frmStructureGenerator.txtMemTagValue.Text = .Rows(aRoeIndex).Cells(0).Value
      ElseIf sCallingControl = "txtMemTagValue1" Then
        frmStructureGenerator.txtMemTagValue1.Text = .Rows(aRoeIndex).Cells(0).Value
      End If
    End With

    Me.Close()

  End Sub

  Private Sub ReturnConstantValues(ByVal aRowIndex As Integer)

    With dgvResult
      If sCallingControl = "txtMemSize1" Then
        frmStructureGenerator.txtMemSize1.Text = .Rows(aRowIndex).Cells(0).Value
      End If
    End With

    Me.Close()

  End Sub

  Private Sub ReturnSubClassNames(ByVal aRowIndex As Integer)

    With dgvResult
      If sCallingControl = "txtMemClassName1" Then
        frmStructureGenerator.txtMemClassName1.Text = .Rows(aRowIndex).Cells(0).Value _
                                                      + ".cls" + .Rows(aRowIndex).Cells(1).Value
      End If
    End With

    Me.Close()

  End Sub

  Private Sub ReturnTables(ByVal aRowIndex As Integer)

    With dgvResult
      If sCallingControl = "txtTableName" Then
        frmIndexGenretor.txtTableName.Text = .Rows(aRowIndex).Cells(0).Value
        frmIndexGenretor.mTableId = .Rows(aRowIndex).Cells(3).Value
      End If
    End With

    Me.Close()

  End Sub

  Private Sub ReturnMdTables(ByVal aRowIndex As Integer)

    With dgvResult
      If sCallingControl = "txtTableName" Then
        frmTableDesign.txtTableName.Text = .Rows(aRowIndex).Cells(0).Value
        frmTableDesign.mIntTableId = .Rows(aRowIndex).Cells(3).Value
      End If
    End With

    Me.Close()

  End Sub

  Private Sub ReturnFKTables(ByVal aRowIndex As Integer)

    With dgvResult
      If sCallingControl = "txtTableName" Then
        frmForeignKeyGenretor.txtTableName.Text = .Rows(aRowIndex).Cells(0).Value
        frmForeignKeyGenretor.mIntTableId = .Rows(aRowIndex).Cells(3).Value
      ElseIf sCallingControl = "txtRefTableName" Then
        frmForeignKeyGenretor.txtRefTableName.Text = .Rows(aRowIndex).Cells(0).Value
        frmForeignKeyGenretor.mIntRefTableId = .Rows(aRowIndex).Cells(3).Value
      End If
    End With

    Me.Close()

  End Sub

  Private Sub SelectDisplayModel()
    Select Case sCallingPurpose
      Case gENMU_PUEPOSE.Tag_Values
        LoadTagValues()
      Case gENMU_PUEPOSE.Constant_Values
        LoadConstantValues()
      Case gENMU_PUEPOSE.Sub_Class_Names
        LoadSubClassNames()
      Case gENMU_PUEPOSE.Main_Classes
        LoadMainClasses()
      Case gENMU_PUEPOSE.Tables, gENMU_PUEPOSE.Md_Tables, gENMU_PUEPOSE.FK_Tables
        LoadTables()
    End Select
  End Sub
  'Events

  Private Sub frmDisplayGrid_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    dgvResult.Rows.Clear()
    SelectDisplayModel()
  End Sub

  Private Sub dgvResult_CellDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvResult.CellDoubleClick

    Select Case sCallingPurpose
      Case gENMU_PUEPOSE.Tag_Values
        ReturnTagValues(e.RowIndex)
      Case gENMU_PUEPOSE.Constant_Values
        ReturnConstantValues(e.RowIndex)
      Case gENMU_PUEPOSE.Sub_Class_Names
        ReturnSubClassNames(e.RowIndex)
      Case gENMU_PUEPOSE.Tables
        ReturnTables(e.RowIndex)
      Case gENMU_PUEPOSE.Md_Tables
        ReturnMdTables(e.RowIndex)
      Case gENMU_PUEPOSE.FK_Tables
        ReturnFKTables(e.RowIndex)
    End Select

  End Sub

  Private Sub cmdSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSearch.Click
    dgvResult.Rows.Clear()
    SelectDisplayModel()
    For Each lObjRow As DataGridViewRow In dgvResult.Rows
      If UCase(lObjRow.Cells(0).Value.ToString).Contains(UCase(txtSearch.Text.Trim)) = False Then
        lObjRow.Visible = False
      End If
    Next
  End Sub

  Private Sub cmdReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdReset.Click
    txtSearch.Clear()
    dgvResult.Rows.Clear()
    SelectDisplayModel()
  End Sub
End Class